


var session=request.getSession();
if(typeof session==='undefined'){


	response.redirect("/login",request,response);
	response.end();

}else if(session.LoggedIn){

		request.user={
			username:session.user["username"],
			name:session.user["name"],
			picture:session.user["picture"]
				
		};

		var bname=request.parameters["name"];
	

		//check if user belongs to the board

		var boardController=request.require("./boardController");
		boardController.getBoardUserPermission(bname,request.user.username,response,cb1);
		

	
}else{
	response.redirect("/login",request,response);
	response.end();

}




function cb1(bname,response){

	if(!bname){
		 response.status = 403 ;
         response.end();
	}else{

//get messages from DB for given boardname
		
		var boardController=request.require("./boardController");
		boardController.queryMessagesfromBoard(bname.board_name,response,cb2);
		}
}





function cb2(board,messages,response){

	
	request.setAttribute("board",board);
	request.setAttribute("msgs",messages);

	response.forward("/board/board.jst",request,response);
	response.end();

}